<!DOCTYPE html>
<html debug="true">
  <head>
    <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
    <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
    <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>

    <script type="text/javascript">
       
        function test_layerrecord(t) {
            t.plan(13);

            var c, layer, record;
            
            c = GeoExt.data.LayerRecord.create();
            t.ok(c instanceof Function, "create returns a func");
            t.eq(c.prototype.fields.items[0].name, "layer",
                 "\"create\" returns a func with a \"layer\" field in its prototype"); 
            t.eq(c.prototype.fields.items[1].name, "title",
                 "\"create\" returns a func with a \"title\" field in its prototype"); 

            c = GeoExt.data.LayerRecord.create([
                {name: "extra1"}, {name: "extra2"}
            ]);
            t.eq(c.prototype.fields.items[0].name, "layer",
                 "\"create(o)\" returns a func with a \"layer\" field in its prototype"); 
            t.eq(c.prototype.fields.items[1].name, "title",
                 "\"create(o)\" returns a func with a \"title\" field in its prototype"); 
            t.eq(c.prototype.fields.items[2].name, "extra1",
                 "\"create(o)\" returns a func with a \"extra1\" field in its prototype"); 
            t.eq(c.prototype.fields.items[3].name, "extra2",
                 "\"create(o)\" returns a func with a \"extra2\" field in its prototype"); 
            t.eq(GeoExt.data.LayerRecord.prototype.fields.items.length, 2,
                 "\create(o)\" method does not modify class prototype's fields");

            layer = new OpenLayers.Layer();
            record = new c({layer: layer, title: layer.name}, layer.id);
            t.ok(record instanceof GeoExt.data.LayerRecord, "create returns a constructor (LayerRecord)");
            t.ok(record instanceof c, "create returns a constructor (c)");
            t.eq(record.get("layer").id, layer.id, "layer stored correctly");
            t.eq(record.id, layer.id, "id set correctly");
            record = new c({layer: layer, title: layer.name, foo: "bar"}, layer.id);
            t.eq(record.get("foo"), "bar", "foo data row set correctly");
        }

         
        function test_clone(t) { 
             
            t.plan(4); 
             
            var layer = new OpenLayers.Layer(); 
            var recordType = GeoExt.data.LayerRecord.create(); 
             
            var record = new recordType({layer: layer, title: layer.name}); 
            var clone = record.clone(); 

            t.ok(clone.id !== record.id, "clone record does not have original id"); 
            t.ok(clone.id == clone.get("layer").id, "clone record id is same as its layer id"); 
             
            record.set("title", "foo"); 
            t.ok(clone.get("title") !== "foo", "setting a property on original doesn't modify clone"); 
             
            t.ok(clone.get("layer") !== layer, "clone does not have original layer"); 
             
        } 
        
    </script>
  <body>
    <div id="mappanel"></div>
  </body>
</html>
